package com.yqg.protection;

import com.yqg.protection.netty.NettyServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.oas.annotations.EnableOpenApi;

@EnableOpenApi
@SpringBootApplication
@EnableScheduling
@EnableAsync
// @EnableWebMvc 访问静态文件不能加这个
public class ProtectionApplication  implements CommandLineRunner {
    private static final Logger LOGGER = LoggerFactory.getLogger(ProtectionApplication.class);

    @Autowired
    NettyServer nettyServer;

    public static void main(String[] args) {
        {
            LOGGER.info("Program begin starting");
            SpringApplication.run(ProtectionApplication.class, args);
            LOGGER.info("Program started successfully!");

        }
    }

    @Override
    public void run(String... args) throws Exception {

        Thread kean = new Thread(new KeanUser());
        kean.start();
    }


    /**
     * 用户信息传输装置
     *
     * @author youngki
     * @date 2022/10/20
     */
    private class KeanUser implements Runnable{

        @Override
        public void run() {
            try {
                nettyServer.startServer(8400);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
